<?php
/**
 * Created by PhpStorm.
 * User: 沁塵
 * Date: 2019/4/20
 * Time: 19:57
 */

namespace app\api\controller\v1;

use app\api\model\MaterialAudio as MaterialAudioModel;
use think\Request;

class MaterialAudio
{

    public function checkMaterialAudio(Request $request) {
        $params = $request->post();
        $event = new MaterialAudioModel();
        $count = $event->where("model", $params["model"])
            ->where("pid", $params["pid"])
            ->where("script_name", $params["script_name"])
            ->where("num", $params["num"])
            ->count();
        if ($count == 0) {
            return writeJson(200, false, '请求成功');
        } else {
            return writeJson(200, true, '请求成功');
        }

    }

    public function addMaterialAudio(Request $request) {
        $params = $request->post();
        $event = new MaterialAudioModel();
        $event->create($params);

        return writeJson(200, '', '请求成功');
    }

    public function getMaterialAudio(Request $request)
    {
        $params = $request->get();
        $event = new MaterialAudioModel();
        $info = $event->where("model", $params["model"])
            ->where("pid", $params["pid"])
            ->where("script_name", $params["script_name"])
            ->where("num", $params["num"])
            ->findOrEmpty();

        return writeJson(200, $info, '请求成功');


    }

    public function upMaterialAudio(Request $request)
    {
        $params = $request->post();
        $res = MaterialAudioModel::where("pid", $params["pid"])
            ->where("script_name", $params["script_name"])->where("num", $params["num"])
            ->where("model", $params["model"])->update(["url"=>$params["url"]]);
        return writeJson(200, $res, '请求成功');

    }

}